﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEulerSolutions
{

    /*
     * 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?

     * 
     * 
     * 
     * */
    class Problem16
    {
        public static string Calculate()
        {
            int limit = 1000;



            int[] lookup = new int[limit];

            lookup[0] = 1;

            for (int i = 0; i < limit; i++)
            {
                int overflow = 0;
                for (int j = 0; j < limit; j++)
                {
                    int num = lookup[j] * 2;
                    lookup[j] = num % 10 + overflow;
                    overflow = num / 10;
                }
            }

            StringBuilder result = new StringBuilder();

            int sum = 0;

            for (int i = limit - 1; i >= 0; i--)
            {
                result.Append(lookup[i]);
                sum += lookup[i];
            }

            return sum.ToString();
        }
    }
}
